<div id="tb<?php echo $uniqid;?>" style="padding:5px">
	<table cellspacing="0" cellpadding="0">
		<tbody>
		<tr>
<!--			<td><a href="javascript:void(0);" onclick="goodscommentAdd();" class="l-btn l-btn-small l-btn-plain"><span-->
<!--					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-tianjia1"></i><span class="l-btn-text">增加</span></span></a></td>-->
<!--			<td>-->
<!--				<div class="datagrid-btn-separator"></div>-->
<!--			</td>-->
			<td><a href="javascript:void(0);" onclick="goodscommentEdit();" class="l-btn l-btn-small l-btn-plain"><span
					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-bianji"></i><span class="l-btn-text">编辑</span></span></a></td>
			<td>
				<div class="datagrid-btn-separator"></div>
			</td>
			<td><a href="javascript:void(0);" onclick="goodscommentDelete();" class="l-btn l-btn-small l-btn-plain"><span
					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-shanchu"></i><span class="l-btn-text">删除</span></span></a></td>
			<td>
				<div class="datagrid-btn-separator"></div>
			</td>
			<td><a href="javascript:void(0);" onclick="goodscommentReload();" class="l-btn l-btn-small l-btn-plain"><span
					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-shuaxin"></i><span class="l-btn-text">重载</span></span></a></td>
			<td>&nbsp&nbsp;<input id="goodscommentKeywords" style="width:200px" type="text" placeholder="请输入商品ID/标题"
								  class="easyui-input textbox"></td>
			<td><a href="javascript:void(0);" onclick="goodscommentSearch();" class="l-btn l-btn-small l-btn-plain"><span
					class="l-btn-left l-btn-icon-left"><i class="iconfont icon-sousuo"></i><span class="l-btn-text">查询</span></span></a></td>
		</tr>
		</tbody>
	</table>
</div>
<div class="con"  style="-moz-user-select:none;">
	<table id="goodscomment"></table>
</div>
<div id="goodscommentdlg" class="easyui-dialog" style="width:720px; height:520px;" title="信息框" closed="true"></div>
<script>
	var goodscommentAdd = function () {
		$("#goodscommentdlg").dialog({
			title: '新增信息',
			closed: false,
			width: 740,
			height: 520,
			cache: false,
			href: '/admin/goodscomment/add',
			modal: true,
			buttons: [{
				text: '保存',
				id: 'goodscommentsubmit',
				iconCls: 'icon-ok',
			}, {
				text: '关闭',
				iconCls: 'icon-no',
				handler: function () {
					$("#goodscommentdlg").dialog('close');
				}
			}]
		});
	};
	var goodscommentEdit = function () {
		var row = $('#goodscomment').datagrid('getSelected');
		if (row) {
			$("#goodscommentdlg").dialog({
				title: '编辑信息',
				closed: false,
				width: 740,
				height: 520,
				cache: false,
				href: '/admin/goodscomment/edit?id=' + row.id,
				modal: true,
				buttons: [{
					text: '保存',
					id: 'goodscommentsubmit',
					iconCls: 'icon-ok',
				}, {
					text: '关闭',
					iconCls: 'icon-no',
					handler: function () {
						$("#goodscommentdlg").dialog('close');
					}
				}]
			});
		} else {
			$.messager.alert('提示', '请先选择要编辑的行！', 'warning');
		}
	};
	var goodscommentDelete = function () {
		var row = $('#goodscomment').datagrid('getSelected');
		if (row) {
			$.messager.confirm('提示', '确定删除吗？', function (r) {
				if (r) {
					$.messager.progress();
					$.post('/admin/goodscomment/delete', {id: row.id}, function (data) {
						$.messager.progress('close');
						if (data.ret === 0) {
							$.messager.show({
								title: '提示',
								msg: data.msg,
								timeout: 3000,
								showType: 'slide'
							});
							goodscommentReload();
						} else {
							$.messager.alert('提示', data.msg, 'warning');
						}
					}, 'json');
				}
			});
		} else {
			$.messager.alert('提示', '请先选择要删除的行！', 'warning');
		}
	};
	var goodscommentReload = function () {
		$("#goodscomment").datagrid('reload');
	};
	var goodscommentSearch = function () {
		var height = $(window).height() - $(".top").height() - 46;
		var width = $(window).width() - $(".leftmenu").width() - 8;
		$("#goodscomment").datagrid({
			title: '商品评论',
			width: width,
			height: height,//高度
			singleSelect: true,//如果为true，则只允许选择一行
			striped: true,//是否显示斑马线效果。
			rownumbers: true,//如果为true，则显示一个行号列。
			pagination: true,//是否显示分页
			pageSize: 10,
			pageList: [10, 15, 20, 25],
			method: 'post',
			sortName: 'id',
			sortOrder: 'desc',
			idField: 'id',
			treeField: 'title',
			url: '/admin/goodscomment/index',
			queryParams: {keywords: $('#goodscommentKeywords').val()},
			fitColumns: true,//真正的自动展开/收缩列的大小，以适应网格的宽度，防止水平滚动。
			nowrap: true,//如果为true，则在同一行中显示数据。设置为true可以提高加载性能。 是否换行
			selectOnCheck: false,
			checkOnSelect: true,
			toolbar: '#tb<?php echo $uniqid;?>',
			columns: [[
				{field:'goods',title:'商品',width:'20%',formatter:function (value,rowData,rowIndex){
					let content = '';
					if(value){
						content = '<div style="display: flex;align-items: center;">' +
						'<img src="' + value.image + '?imageView2/1/w/50/h/50" style="height:50px;width:50px;border-radius: 5px;border:#dfdfdf 1px solid;">'+
						'<div style="width: calc(100% - 55px); padding-left: 5px; white-space: pre-wrap;">商品ID：' + rowData.goods_id + '<br>' + value.title + '</div></div>';
					}
					return content;
				}},
				{field:'member',title:'用户',width:'7%',formatter:function (value,rowData,rowIndex){
						return rowData ? rowData.member.nickname : '';
					}},
				{field:'images',title:'图片',width:'15%',formatter:function (value,rowData,rowIndex){
					if(value) {
						let images = value.split(',');
						let rt = '';
						for (let i in images) {
							rt += '<img height="60px" src="' + images[i] + '">';
						}
						return rt;
					}
					}},
				{field:'level',title:'评分',width:'5%',sortable:true},
				{field:'content',title:'评论内容',width:'15%'},
				{field:'created_at',title:'评论时间',width:'10%',sortable:true},
				{field:'reply_content',title:'回复内容',width:'10%'},
				{field:'replied_at',title:'回复时间',width:'10%',sortable:true},
				{field:'status',title:'状态',width:'5%',formatter:function (value,rowData,rowIndex){
						return value==='show' ? '显示' : '隐藏';
					}},
			]],
			onDblClickRow: function (index, field) {
				goodscommentEdit();
			}
		});
	};
	onDatagridResize("#goodscomment");
	goodscommentSearch();
</script>
